<template>
	<div class="">
		
	    
		<el-form :model="ruleForm" :rules="rules" ref="ruleForm" class="loginContainer">
			<h3 class="loginTitle">超市进销存管理登录</h3>
		  <el-form-item label="账号" prop="ename" >
			<el-input v-model="ruleForm.ename"></el-input>
		  </el-form-item>
		  <el-form-item label="密码" prop="epassword" type="password" >
			<el-input type="password" v-model="ruleForm.epassword"></el-input>
		  </el-form-item>
		 
		 
		  <el-form-item>
			<el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
			<el-button @click="resetForm('ruleForm')">重置</el-button>
		  </el-form-item>
		</el-form>
		
	</div>	
</template>

<script>
  export default {
    data() {
      return {
        ruleForm: {
          ename: 'admin',
          epassword: '123456'
        },
        rules: {
          mnum: [
            { required: true, message: '请输入账号', trigger: 'blur' },
          ],
          mpassword: [
            { required: true, message: '请输入密码', trigger: 'blur' },
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
		const _this=this
        this.$refs[formName].validate((valid) => {
          if (valid) {
            axios.get('http://localhost:8181/employee/login/'+_this.ruleForm.ename+'/'+_this.ruleForm.epassword).then(function(resp){
				console.log(resp)
				if(_this.ruleForm.ename == "admin" && _this.ruleForm.epassword == "123456")
				{
					_this.$router.push('/Administrator')
					_this.$message('管理员登录成功！');
				}
				else if(resp.data == 'success'){
					
					_this.$router.push('/User')
					_this.$message('员工登录成功！');
				}
				else{
					alert('用户名或密码错误,  请重新输入！！！')
					window.location.reload()
				}
			})
          } else {
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style>
  .loginContainer{
    border-radius: 15px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 15px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }
  .loginTitle{
    margin: 4px auto 20px auto;
    text-align: center;
  }
</style>